/*
 * WaitWhileTranslatingDialog.java
 *
 * Created on July 17, 2008, 12:04 PM
 */

package com.elysian.translator;

import java.awt.Dimension;
import java.awt.Toolkit;

/**
 *
 * @author  ydubey
 */
public class WaitWhileTranslatingDialog extends javax.swing.JDialog {
    
    private TranslatorUI.TranslatorThread translatorThread;
    
    /** Creates new form WaitWhileTranslatingDialog */
    public WaitWhileTranslatingDialog(TranslatorUI translatorUI, TranslatorUI.TranslatorThread translatorThread) {
        super(translatorUI);
        translatorUI.setEnabled(false);
        this.translatorThread = translatorThread;
        initComponents();
        setSize(410, 120);
        int x, y;
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        x = new Double(d.getWidth()).intValue();
        y = new Double(d.getHeight()).intValue();
        x = (x / 2) - (getWidth() / 2);
        y = (y / 2) - (getHeight() / 2);
        setLocation(x, y);
        setVisible(true);
    }

    void showTranslationAbsolute(String source) {
        translationLabel.setText(source);
    }

    void showTranslationTarget(String targetTranslation) {
        translationTargetLabel.setText("<html>Target: <i>"+targetTranslation+"</i></html>");
    }

    void showTranslation(String source) {
        translationLabel.setText("<html>Text: <i>"+source+"</i></html>");
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        translationTargetLabel = new javax.swing.JLabel();
        translationProgressBar = new javax.swing.JProgressBar();
        translationLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Translation In Progress...");
        setFont(TranslatorUI.font);
        setResizable(false);
        getContentPane().setLayout(null);

        translationTargetLabel.setFont(TranslatorUI.font);
        translationTargetLabel.setText("Translating:");
        getContentPane().add(translationTargetLabel);
        translationTargetLabel.setBounds(10, 10, 380, 14);

        translationProgressBar.setFont(TranslatorUI.font);
        translationProgressBar.setIndeterminate(true);
        getContentPane().add(translationProgressBar);
        translationProgressBar.setBounds(10, 30, 380, 18);

        translationLabel.setFont(TranslatorUI.font);
        translationLabel.setText("Translating Text:");
        getContentPane().add(translationLabel);
        translationLabel.setBounds(10, 60, 300, 14);

        cancelButton.setFont(TranslatorUI.font);
        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        getContentPane().add(cancelButton);
        cancelButton.setBounds(310, 56, 80, 23);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        translatorThread.kill();
    }//GEN-LAST:event_cancelButtonActionPerformed
    
    @Override
    public void dispose() {
        getParent().setEnabled(true);
        super.dispose();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel translationLabel;
    private javax.swing.JProgressBar translationProgressBar;
    private javax.swing.JLabel translationTargetLabel;
    // End of variables declaration//GEN-END:variables
    
}
